#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

int main()
{
    int fd[2];
    int ret = pipe(fd);
    if(ret < 0)
    {
        perror("pipe");
        return 0;
    }
    int flag = fcntl(fd[0],F_GETFL);
    fcntl(fd[0],F_SETFL,flag | O_NONBLOCK);
    flag = fcntl(fd[0],F_GETFL);
    pid_t pid = fork();
    if(pid < 0)
    {
        perror("fork");
        return 0;
    }
    else if(pid == 0)
    {
        //child
        //写端不关闭
        //写端关闭
        close(fd[1]);
        char* buf[1024]={0};
        size_t size = read(fd[0],buf,sizeof(buf)-1);
        printf("size:%ld\n",size);
    }
    else 
    {
        //father
        close(fd[1]);
        sleep(10);
    }
}
